<?php

namespace lib\App;

use app\Controller\sys\info;
use lib\Root;

class Controller
{
	public $http;
	public $response;
	public $request;
	public $params;
	public $config;

	#DatabaseConnection
	public $redis = null;
	public $asynRedis = null;
	public $mysql = null;
	public $asynMysql = null;

	public function __construct($http = false)
	{
		if (false !== $http) {
			$this->http     = $http;
			$this->request  = $http->request;
			$this->response = $http->response;
			$this->params   = \Router::$params;
		}

		$this->config = \Spyc::YAMLLoad(ROOT_DIR . DIRECTORY_SEPARATOR . 'app/_app.yaml');
	}

	public function getParams($paramName)
	{
		return $this->params[$paramName] ?? null;
	}

	/**
	 * @param $time
	 * @param $callback
	 */
	public function setInterval($time, $callback)
	{
		swoole_timer_tick($time, $callback);
	}

	public function getConfig($key){
		return Root::Config($key);
	}
}